import {createSlice, current} from '@reduxjs/toolkit'
import { componentsData } from '../../mock/data'
import {admmData} from '../../data/ToolXHL'
 let Imgadd=[]
const todosSlice=createSlice({


    name:'counter',
    initialState:{
        num:0,
        componentsText:componentsData[0],
        componentsBtn:componentsData[1],
        componentsData:componentsData[2],

        actionID:null,
        currentXHLS:[],
        currentXHL:[] as any,

        newaddome:[],
        admmData
    },
    reducers :{
        // 添加图片至画布
        addCanvas(state,action){
            state.currentXHL.push(action)
        },
        // 选中
       setItemMoudle(state,action){
        state.currentXHLS=action.payload
       },
    //    点击背景
        clickimg(state,action){
            Imgadd=[];
            Imgadd.push(action.payload);
            state.newaddome=Imgadd[0];
        },
        //  updateItem(state,action){
        //     state.currentXHLS=action.payload
        // },
        // 清空画布 
        AllDel(state:any){
            state.currentXHL=[];
            state.newaddome=[]
        },
      
        // 裁剪
        updataImage(state:any,action){
            console.log(action,'少嘚瑟发');
            const index=state.currentXHL.findIndex((item:any) => {
                return item.payload.id===state.id
            })
            state.currentXHL[index].payload.style={
                ...state.currentXHL[index].payload.style,
                ...action.payload
            }
            state.currentXHL[index].payload.propLable=action.payload.image
        }
        
    }
})
export const {addCanvas,setItemMoudle,clickimg,updateItem,AllDel,updataImage}=todosSlice.actions
export default todosSlice.reducer